﻿using System.Web.UI;

namespace TTQT.Administration
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    /// <summary>
    ///		Summary description for Welcome.
    /// </summary>
    public partial class Welcome : MasterControl//System.Web.UI.UserControl
    {

        private void visibleRows(string role)
        {
            if (isRole("ttv"))
            {
                if (!lblXuatdieuchuyenGDV.Text.Equals("0"))
                    trXuatdieuchuyenGDV.Visible = true;

                if (!lblXuatcaptrenGDV.Text.Equals("0"))
                    trXuatcaptrenGDV.Visible = true;

                if (!lblXuatkhachhang.Text.Equals("0"))
                    trXuatkhachhang.Visible = true;

                if (!lblNhapKhoGDV.Text.Equals("0"))
                    trNhapKhoGDV.Visible = true;

                if (!lblDoiTrangThai.Text.Equals("0"))
                    trDoiTrangThai.Visible = true;
                if (trXuatdieuchuyenGDV.Visible || trXuatcaptrenGDV.Visible || trXuatkhachhang.Visible || trNhapKhoGDV.Visible || trDoiTrangThai.Visible)
                {
                    pnChao.Visible = false;
                    pnCongViec.Visible = true;
                }
                else
                {
                    pnChao.Visible = true;
                    pnCongViec.Visible = false;
                }
            }
            if (isRole("ksv"))
            {
                if (!lblDuyetPhatHanh.Text.Equals("0"))
                    trDuyetPhatHanh.Visible = true;

                if (!lblDuyetXuatKho.Text.Equals("0"))
                    trDuyetXuatKho.Visible = true;

                if (!lblDuyetNhapKho.Text.Equals("0"))
                    trDuyetNhapKho.Visible = true;

                if (!lblDuyetDoiTrangThaiAC.Text.Equals("0"))
                    trDuyetDoiTrangThaiAC.Visible = true;

                if (!lblDuyetKhaiBaoTonKho.Text.Equals("0"))
                    trDuyetKhaiBaoTonKho.Visible = true;
                if (trDuyetPhatHanh.Visible || trDuyetXuatKho.Visible || trDuyetNhapKho.Visible || trDuyetDoiTrangThaiAC.Visible || trDuyetKhaiBaoTonKho.Visible)
                {
                    pnChao.Visible = false;
                    pnCongViec.Visible = true;
                }
                else
                {
                    pnChao.Visible = true;
                    pnCongViec.Visible = false;
                }
            }
            if (isRole("quychinh"))
            {
                if (!lblPhatHanh.Text.Equals("0"))
                    trPhatHanh.Visible = true;

                if (!lblDoiTrangThai.Text.Equals("0"))
                    trDoiTrangThai.Visible = true;

                if (!lblXuatdieuchuyen.Text.Equals("0"))
                    trXuatdieuchuyen.Visible = true;

                if (!lblXuatphanphoichoPGD.Text.Equals("0"))
                    trXuatphanphoichoPGD.Visible = true;

                if (!lblXuatcaptren.Text.Equals("0"))
                    trXuatcaptren.Visible = true;

                if (!lblXuattieuhuy.Text.Equals("0"))
                    trXuattieuhuy.Visible = true;

                if (!lblNhapKho.Text.Equals("0"))
                    trNhapKho.Visible = true;

                if (trPhatHanh.Visible || trDoiTrangThai.Visible || trXuatdieuchuyen.Visible || trXuatphanphoichoPGD.Visible || trXuatcaptren.Visible || trXuattieuhuy.Visible || trNhapKho.Visible)
                {
                    pnChao.Visible = false;
                    pnCongViec.Visible = true;
                }
                else
                {
                    pnChao.Visible = true;
                    pnCongViec.Visible = false;
                }
            }
            if (isRole("quychinhkhodaumoi"))
            {
                if (!lblPhatHanh.Text.Equals("0"))
                    trPhatHanh.Visible = true;

                if (!lblDoiTrangThai.Text.Equals("0"))
                    trDoiTrangThai.Visible = true;

                if (!lblXuatPhanPhoiChoCN.Text.Equals("0"))
                    trXuatPhanPhoiChoCN.Visible = true;

                if (!lblXuatphanphoichoPGD.Text.Equals("0"))
                    trXuatphanphoichoPGD.Visible = true;

                if (!lblXuattieuhuy.Text.Equals("0"))
                    trXuattieuhuy.Visible = true;

                if (!lblNhapKho.Text.Equals("0"))
                    trNhapKho.Visible = true;

                if (trPhatHanh.Visible || trDoiTrangThai.Visible || trXuatPhanPhoiChoCN.Visible || trXuatphanphoichoPGD.Visible || trXuattieuhuy.Visible || trNhapKho.Visible)
                {
                    pnChao.Visible = false;
                    pnCongViec.Visible = true;
                }
                else
                {
                    pnChao.Visible = true;
                    pnCongViec.Visible = false;
                }
            }
            if (isRole("quychinhphonggiaodich"))
            {
                if (!lblDoiTrangThai.Text.Equals("0"))
                    trDoiTrangThai.Visible = true;

                if (!lblXuatdieuchuyen.Text.Equals("0"))
                    trXuatdieuchuyen.Visible = true;

                if (!lblXuatphanphoichoGDV.Text.Equals("0"))
                    trXuatphanphoichoGDV.Visible = true;

                if (!lblXuatcaptren.Text.Equals("0"))
                    trXuatcaptren.Visible = true;

                if (!lblNhapKho.Text.Equals("0"))
                    trNhapKho.Visible = true;

                if (trDoiTrangThai.Visible || trXuatdieuchuyen.Visible || trXuatphanphoichoGDV.Visible || trXuatcaptren.Visible || trNhapKho.Visible)
                {
                    pnChao.Visible = false;
                    pnCongViec.Visible = true;
                }
                else
                {
                    pnChao.Visible = true;
                    pnCongViec.Visible = false;
                }
            }
        }

        private void layDuLieuChoMoiCongViecVaHienNhungDongCoViec()
        {
            DataTable t = TTQT_Code.TTQTCommon.GetSoLuongAnChi(UserInfo.MaKho, UserInfo.userName);

            if (null != t)
            {
                if (t.Rows.Count > 0)
                {
                    int phatHanh = 0;
                    int Duyetphathanh = 0;
                    int Duyetxuatkho = 0;
                    int Duyetnhapkho = 0;
                    int DuyetdoitrangthaiAC = 0;
                    int NhapKho = 0;
                    int DuyetKhaiBaoTonKho = 0;
                    int XuatphanphoichoCN = 0;
                    int Xuatdieuchuyen = 0;
                    int XuatdieuchuyenGDV = 0;
                    int XuatphanphoichoPGD = 0;
                    int XuatphanphoichoGDV = 0;
                    int Xuatcaptren = 0;
                    int XuatcaptrenGDV = 0;
                    int Xuattieuhuy = 0;
                    int Xuatkhachhang = 0;
                    int DoiTrangThai = 0;
                    int NhapKhoGDV = 0;
                    phatHanh = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["phathanh"], 0);
                    Duyetphathanh = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Duyetphathanh"], 0);
                    Duyetxuatkho = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Duyetxuatkho"], 0);
                    Duyetnhapkho = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Duyetnhapkho"], 0);
                    DuyetdoitrangthaiAC = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["DuyetdoitrangthaiAC"], 0);
                    NhapKho = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["NhapKho"], 0);
                    DuyetKhaiBaoTonKho = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["DuyetKhaiBaoTonKho"], 0);
                    XuatphanphoichoCN = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["XuatphanphoichoCN"], 0);
                    Xuatdieuchuyen = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Xuatdieuchuyen"], 0);
                    XuatdieuchuyenGDV = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["XuatdieuchuyenGDV"], 0);
                    XuatphanphoichoPGD = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["XuatphanphoichoPGD"], 0);
                    XuatphanphoichoGDV = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["XuatphanphoichoGDV"], 0);
                    Xuatcaptren = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Xuatcaptren"], 0);
                    XuatcaptrenGDV = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["XuatcaptrenGDV"], 0);
                    Xuattieuhuy = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Xuattieuhuy"], 0);
                    Xuatkhachhang = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["Xuatkhachhang"], 0);
                    DoiTrangThai = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["DoiTrangThai"], 0);
                    NhapKhoGDV = TTQT_Code.TTQTCommon.ToInt32(t.Rows[0]["NhapKhoGDV"], 0);
                    lblPhatHanh.Text = phatHanh.ToString();
                    lblDuyetPhatHanh.Text = Duyetphathanh.ToString();
                    lblDuyetXuatKho.Text = Duyetxuatkho.ToString();
                    lblDuyetNhapKho.Text = Duyetnhapkho.ToString();
                    lblDuyetDoiTrangThaiAC.Text = DuyetdoitrangthaiAC.ToString();
                    lblNhapKho.Text = NhapKho.ToString();
                    lblDuyetKhaiBaoTonKho.Text = DuyetKhaiBaoTonKho.ToString();
                    lblXuatPhanPhoiChoCN.Text = XuatphanphoichoCN.ToString();
                    lblXuatdieuchuyen.Text = Xuatdieuchuyen.ToString();
                    lblXuatdieuchuyenGDV.Text = XuatdieuchuyenGDV.ToString();
                    lblXuatphanphoichoPGD.Text = XuatphanphoichoPGD.ToString();
                    lblXuatphanphoichoGDV.Text = XuatphanphoichoGDV.ToString();
                    lblXuatcaptren.Text = Xuatcaptren.ToString();
                    lblXuatcaptrenGDV.Text = XuatcaptrenGDV.ToString();
                    lblXuattieuhuy.Text = Xuattieuhuy.ToString();
                    lblXuatkhachhang.Text = Xuatkhachhang.ToString();
                    lblDoiTrangThai.Text = DoiTrangThai.ToString();
                    lblNhapKhoGDV.Text = NhapKhoGDV.ToString();

                    /*
                    if (trPhatHanh.Visible)
                        trPhatHanh.Visible = phatHanh != 0 ? true : false;

                    if (trDuyetPhatHanh.Visible)
                        trDuyetPhatHanh.Visible = Duyetphathanh != 0 ? true : false;

                    if (trDuyetXuatKho.Visible)
                        trDuyetXuatKho.Visible = Duyetxuatkho != 0 ? true : false;

                    if (trDuyetNhapKho.Visible)
                        trDuyetNhapKho.Visible = Duyetnhapkho != 0 ? true : false;

                    if (trDuyetDoiTrangThaiAC.Visible)
                        trDuyetDoiTrangThaiAC.Visible = DuyetdoitrangthaiAC != 0 ? true : false;

                    if (trNhapKho.Visible)
                        trNhapKho.Visible = NhapKho != 0 ? true : false;

                    if (trDuyetKhaiBaoTonKho.Visible)
                        trDuyetKhaiBaoTonKho.Visible = DuyetKhaiBaoTonKho != 0 ? true : false;

                    if (trXuatPhanPhoiChoCN.Visible)
                        trXuatPhanPhoiChoCN.Visible = XuatphanphoichoCN != 0 ? true : false;

                    if (trXuatdieuchuyen.Visible)
                        trXuatdieuchuyen.Visible = Xuatdieuchuyen != 0 ? true : false;

                    if (trXuatdieuchuyenGDV.Visible)
                        trXuatdieuchuyenGDV.Visible = XuatdieuchuyenGDV != 0 ? true : false;

                    if (trXuatphanphoichoPGD.Visible)
                        trXuatphanphoichoPGD.Visible = XuatphanphoichoPGD != 0 ? true : false;

                    if (trXuatphanphoichoGDV.Visible)
                        trXuatphanphoichoGDV.Visible = XuatphanphoichoGDV != 0 ? true : false;

                    if (trXuatcaptren.Visible)
                        trXuatcaptren.Visible = Xuatcaptren != 0 ? true : false;

                    if (trXuatcaptrenGDV.Visible)
                        trXuatcaptrenGDV.Visible = XuatcaptrenGDV != 0 ? true : false;

                    if (trXuattieuhuy.Visible)
                        trXuattieuhuy.Visible = Xuattieuhuy != 0 ? true : false;

                    if (trXuatkhachhang.Visible)
                        trXuatkhachhang.Visible = Xuatkhachhang != 0 ? true : false;

                    if (trDoiTrangThai.Visible)
                        trDoiTrangThai.Visible = DoiTrangThai != 0 ? true : false;

                    if (trNhapKhoGDV.Visible)
                        trNhapKhoGDV.Visible = NhapKhoGDV != 0 ? true : false;
                        */
                }
            }
        }
        private void hideAllRows()
        {
            trPhatHanh.Visible = false;
            trDuyetPhatHanh.Visible = false;
            trDuyetXuatKho.Visible = false;
            trDuyetNhapKho.Visible = false;
            trDuyetDoiTrangThaiAC.Visible = false;
            trNhapKho.Visible = false;
            trDuyetKhaiBaoTonKho.Visible = false;
            trXuatPhanPhoiChoCN.Visible = false;
            trXuatdieuchuyen.Visible = false;
            trXuatdieuchuyenGDV.Visible = false;
            trXuatphanphoichoPGD.Visible = false;
            trXuatphanphoichoGDV.Visible = false;
            trXuatcaptren.Visible = false;
            trXuatcaptrenGDV.Visible = false;
            trXuattieuhuy.Visible = false;
            trXuatkhachhang.Visible = false;
            trDoiTrangThai.Visible = false;
            trNhapKhoGDV.Visible = false;
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {

            hideAllRows();
            layDuLieuChoMoiCongViecVaHienNhungDongCoViec();
            if (isRole("ttv"))
            {
                visibleRows("ttv");
            }
            else if (isRole("ksv"))
            {
                visibleRows("ksv");
            }
            else if (isRole("quychinh"))
            {
                visibleRows("quychinh");
            }
            else if (isRole("quychinhkhodaumoi"))
            {
                visibleRows("quychinhkhodaumoi");
            }
            else if (isRole("quychinhphonggiaodich"))
            {
                visibleRows("quychinhphonggiaodich");
            }
            else
            {
                pnChao.Visible = true;
                pnCongViec.Visible = false;
            }
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }
        #endregion
    }
}
